import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from logisitic_regression import Logistic_Regression

data_set = pd.read_csv('https://www.gairuo.com/file/data/dataset/iris.data')
print(data_set)
x1_axis = 'petal_length'
x2_axis = 'petal_width'
y_axis = 'species'
unique_classes = np.unique(data_set[y_axis])
print(unique_classes)
for iris_type in unique_classes:
    plt.scatter(data_set[x1_axis][data_set[y_axis]==iris_type],
                data_set[x2_axis][data_set[y_axis]==iris_type],
                label=iris_type
    )   
plt.show()
x_train = data_set[[x1_axis,x2_axis]].values.reshape((data_set.shape[0],2))
y_train = data_set[y_axis].values.reshape((data_set.shape[0],1))
logreg = Logistic_Regression(x_train,y_train)
all_cost_history = logreg.train()
plt.plot(range(len(all_cost_history[0])),all_cost_history[0],label=logreg.unique_labels[0])
plt.plot(range(len(all_cost_history[1])),all_cost_history[1],label=logreg.unique_labels[1])
plt.plot(range(len(all_cost_history[2])),all_cost_history[2],label=logreg.unique_labels[2])
plt.show()

y_predict = logreg.predict(x_train)
precision = np.sum(y_predict==y_train)/y_train.shape[0]
print(precision) 